package recite.word.client.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import recite.word.client.dto.login.*;
import recite.word.client.service.ILoginService;
import recite.word.client.vo.login.LoginVO;
import recite.word.client.vo.login.LoginVerifyPhoneVO;
import recite.word.service.base.common.request.BaseRequest;
import recite.word.service.base.common.response.ResponseResult;

@RestController
@RequestMapping("/client/login")
@Api(tags = "客户端【用户登录】Controller")
public class LoginController {
    @Autowired
    private ILoginService loginService;

    @PostMapping("/login")
    @ApiOperation("用户登录")
    public ResponseResult<LoginVO> login(@RequestBody BaseRequest<LoginDTO> dto){
        LoginVO ans = loginService.login(dto);
        return ResponseResult.success(ans);
    }

    @PostMapping("/verifyPhone")
    @ApiOperation("验证手机号是否已注册")
    public ResponseResult<LoginVerifyPhoneVO> verifyPhone(@RequestBody BaseRequest<LoginVerifyPhoneDTO> dto) {
        LoginVerifyPhoneVO ans = loginService.verifyPhone(dto);
        return ResponseResult.success(ans);
    }

    @PostMapping("/sendCode")
    @ApiOperation("发送验证码")
    public ResponseResult sendCode(@RequestBody BaseRequest<LoginSendCodeDTO> dto) {
        loginService.sendCode(dto);
        return ResponseResult.success("发送成功");
    }

    @PostMapping("/register")
    @ApiOperation("注册")
    public ResponseResult register(@RequestBody BaseRequest<LoginRegisterDTO> dto) {
        loginService.register(dto);
        return ResponseResult.success("注册成功");
    }

    @PostMapping("/forgot")
    @ApiOperation("忘记密码")
    public ResponseResult forgot(@RequestBody BaseRequest<LoginForgotDTO> dto) {
        loginService.forgot(dto);
        return ResponseResult.success("更新密码成功");
    }
}
